package com.wk.wanjetpack.net

import androidx.paging.ExperimentalPagingApi
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.RemoteMediator
import com.wk.base.PAGE_SIZE
import com.wk.wanjetpack.bean.Article
import com.wk.wanjetpack.db.AppDataBase
import javax.inject.Inject

/**
 * @author peng
 * @date 2021/1/21
 * 说明
 */
class MainRepo @Inject constructor(private val api:IApi) {

    @ExperimentalPagingApi
    val remoteMediator : RemoteMediator<Int,Article> by lazy {
        ArticleRemoteMediator(api)
    }

    @ExperimentalPagingApi
    fun getArticles() = Pager(PagingConfig(pageSize = PAGE_SIZE,enablePlaceholders = true,prefetchDistance = 3),null,remoteMediator = null){
            ArticleDataSource(api)
    }.flow

}